﻿#ifndef GEOMTURBODATAEXCHANGE_H
#define GEOMTURBODATAEXCHANGE_H

#include "GeometryThreadBase.h"
#include <QFile>
#include <QObject>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>

namespace GUI
{
	class MainWindow;
}

namespace Geometry
{
	enum class SplineType : int
	{
		Unknown = 0,
		BSpline,				  /// 均匀B样条曲线
		QuasiBSpline,			  /// 准均匀B样条曲线
		SegmentedBezier,		  /// 分段贝塞尔曲线
		NonUniformRationalBSpline /// 非均匀有理B样条曲线
	};

	class GEOMETRYDATAEXCHANGEAPI GeomTurboDataExchange : public GeometryThreadBase
	{
		Q_OBJECT

	public:
		GeomTurboDataExchange(const QString &_fileName, GeometryOperation operation, GUI::MainWindow *mw, QList<GeometrySet *> &res, int KernalId = -1);
		~GeomTurboDataExchange() = default;
		void run() override;

		void setFirstThreadFlag(bool flag);

	private:
		bool readGeomTurbo();
		bool writeGeomTurbo();
		void deriveGeometryTaskFinished();

		bool parseHubData(QFile &file);
		bool parseShroudData(QFile &file);
		bool parseSuctionData(QFile &file);
		bool parsePressureData(QFile &file);
		QList<double> zrToXyz(double z, double r);
		QList<QList<double>> parseSectionData(QFile &file, bool *ok = nullptr);
		TopoDS_Edge createSpline(QList<QList<double>> points, SplineType type = SplineType::BSpline);

	signals:
		void updateMeshRowTreeSig();

	private:
		const QString _fileName;
		GeometryOperation _operation;
		bool _isRead{ false };
		bool _isWrite{ false };
		/// 错误信息
		QString m_ErrorString = "";
		/// 叶根数据hub（Z=轴向，R=径向）
		QList<QList<double>> m_Hub = {};
		/// 叶顶数据shroud（Z=轴向，R=径向）
		QList<QList<double>> m_Shroud = {};
		/// 叶片数据blade（X=径向，Y=周向，Z=轴向）
		QList<QList<QList<double>>> m_Suction = {};
		QList<QList<QList<double>>> m_Pressure = {};
		/// 叶片数量
		int m_NumOfBlades = 0;
		/// 叶片数量
		double m_Tolerance = 1e-006;
		bool m_FirstThreadFlag = true;

		GUI::MainWindow *_mainWindow = nullptr;
	};
}

#endif